home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / TupleDatabase / DiskEntry.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  4.3 KB  |  178 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DiskEntry.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef    __DISKENTRY__
  15. #define    __DISKENTRY__
  16.  
  17. #ifndef    __TYPES__
  18. #include "Types.h"
  19. #endif
  20.  
  21. #ifndef    __GMTTIME__
  22. #include "GMTTime.h"
  23. #endif
  24.  
  25. #ifndef    __DIRECTOBJECT__
  26. #include "DirectObject.h"
  27. #endif
  28.  
  29. class ostream;
  30. class TAbstractFile;
  31.  
  32. /***********************************|****************************************/
  33.  
  34. typedef unsigned long EntryID;
  35.  
  36. class TLogEntry : public TDirectObject
  37. {
  38. public:
  39.  
  40.     static const EntryID kInvalidID;
  41.  
  42.             TLogEntry ();
  43.             TLogEntry ( const TLogEntry& );
  44.     virtual    ~TLogEntry ();
  45.  
  46.             TLogEntry&                operator = ( const TLogEntry& );
  47.             Boolean                    operator == ( const TLogEntry& ) const;
  48.             Boolean                    operator != ( const TLogEntry& ) const;
  49.  
  50.             EntryID                    GetID () const;
  51.             void                    GetTimeStamp ( TTimeStamp& ) const;
  52.             const TTimeStamp&        GetTimeStamp () const;
  53.  
  54.     virtual    unsigned long            GetTextLength () const;
  55.     virtual    void                    GetText ( char* buffer, unsigned long size ) const;
  56.     virtual    char*                    CreateText () const;
  57.  
  58.     virtual    Boolean                    WriteTo ( TAbstractFile& ) const;
  59.     virtual    Boolean                    ReadFrom ( TAbstractFile& );
  60.  
  61.     virtual    ostream&                operator >> ( ostream& ) const;
  62.  
  63. protected:
  64.  
  65.     virtual    const char*                GetClass () const;    // all subclasses must override
  66.  
  67. private:    EntryID                    fID;
  68.             TTimeStamp                fTime;
  69.             char*                    fCache;
  70.  
  71.     friend class TDiskLog;
  72. };
  73.  
  74. /***********************************|****************************************/
  75.  
  76. class TTestEntry : public TLogEntry
  77. {
  78. public:        TTestEntry ();    // has random length
  79.             TTestEntry ( unsigned long length );
  80.             TTestEntry ( const TTestEntry& );
  81.     virtual    ~TTestEntry ();
  82.  
  83.             TTestEntry&                operator = ( const TTestEntry& );
  84.             Boolean                    operator == ( const TTestEntry& ) const;
  85.             Boolean                    operator != ( const TTestEntry& ) const;
  86.  
  87.     virtual    Boolean                    WriteTo ( TAbstractFile& ) const;
  88.     virtual    Boolean                    ReadFrom ( TAbstractFile& );
  89.  
  90.     virtual    ostream&                operator >> ( ostream& ) const;
  91.  
  92. protected:
  93.  
  94.     static    const unsigned long kChunkSize;
  95.  
  96.     virtual    const char*                GetClass () const;    // all subclasses must override
  97.  
  98.     static    unsigned long            RandomLength ( unsigned long min = 0, unsigned long max = 128 );
  99.     static    void                    FillBuffer ( char*, unsigned long );
  100.     static    Boolean                    VerifyBuffer ( char*, unsigned long );
  101.  
  102. private:    unsigned long            fLength;
  103. };
  104.  
  105. /***********************************|****************************************/
  106.  
  107. class TErrorEntry : public TLogEntry
  108. {
  109. public:        TErrorEntry ();
  110.             TErrorEntry ( const char* file, unsigned long line, const char* message = nil );
  111.             TErrorEntry ( const TErrorEntry& );
  112.     virtual    ~TErrorEntry ();
  113.             TErrorEntry&            operator = ( const TErrorEntry& );
  114.  
  115.     virtual    unsigned long            GetTextLength () const;
  116.     virtual    void                    GetText ( char* buffer, unsigned long size ) const;
  117.     virtual    char*                    CreateText () const;
  118.  
  119.     virtual    Boolean                    WriteTo ( TAbstractFile& ) const;
  120.     virtual    Boolean                    ReadFrom ( TAbstractFile& );
  121.  
  122.     virtual    ostream&                operator >> ( ostream& ) const;
  123.  
  124. protected:
  125.  
  126.     virtual    const char*                GetClass () const;    // all subclasses must override
  127.     virtual    unsigned long            GetString ( char* buffer ) const;    // returns length
  128.     virtual    Boolean                    Write ( const char*, TAbstractFile& ) const;
  129.     virtual    Boolean                    Read ( char*&, TAbstractFile& ) const;
  130.  
  131. private:    char*                    fFile;
  132.             unsigned long            fLine;
  133.             char*                    fMessage;
  134. };
  135.  
  136. /***********************************|****************************************/
  137. /***********************************|****************************************/
  138.  
  139. #pragma push
  140. #pragma segment DiskLog
  141.  
  142. /***********************************|****************************************/
  143.  
  144. inline
  145. TLogEntry::~TLogEntry ()
  146. {
  147.     delete fCache;
  148. }
  149.  
  150. /***********************************|****************************************/
  151.  
  152. inline EntryID
  153. TLogEntry::GetID () const
  154. {
  155.     return fID;
  156. }
  157.  
  158. /***********************************|****************************************/
  159.  
  160. inline void
  161. TLogEntry::GetTimeStamp ( TTimeStamp& time ) const
  162. {
  163.     time = fTime;
  164. }
  165.  
  166. /***********************************|****************************************/
  167.  
  168. inline const TTimeStamp&
  169. TLogEntry::GetTimeStamp () const
  170. {
  171.     return fTime;
  172. }
  173.  
  174. /***********************************|****************************************/
  175.  
  176. #pragma pop
  177.  
  178. #endif    // __LOGENTRY__